local qunxian3__hanniba_pengren = fk.CreateSkill {
  name = "qunxian3__hanniba_pengren",
}

Fk:loadTranslationTable {
  ["qunxian3__hanniba_pengren"] = "烹饪",
  [":qunxian3__hanniba_pengren"] = [[出牌阶段，你可以对一名其他角色使用手牌中所有的【杀】:对其造成伤害时令其本回合所有技能失效，然后其翻至背面，你获得其一个技能。
  最后你播放【烹饪】の小曲，将随机数量的【食材】标记变更为等量随机不重复的【食物】标记（豆腐花，炸翅膀，牛排，煎蛋）。]],
  ["@[qunxian3__hanniba_pengren]"] = "食物",
  ["@@qunxian3__hanniba_pengren-card"] = "烹饪",
  ['#qunxian3__hanniba_pengren-use_slash'] = '烹饪:你可以对一名其他角色使用手牌中所有的【杀】',
  ["#qunxian3__hanniba_pengren-damage_slash"] = "烹饪：你可以令其本回合所有技能失效，然后其翻至背面，你获得其一个技能。",
  ["#qunxian3__hanniba_pengren-choose_skill"] = "烹饪：你可以获得其一个技能"
}

qunxian3__hanniba_pengren:addEffect("active", {
  mute = true,
  target_num = 1,
  prompt = "#qunxian3__hanniba_pengren-use_slash",
  target_filter = function(self, player, to_select, selected, selected_cards, card, extra_data)
    return to_select ~= player and
        player:canUseTo(Fk:cloneCard("slash"), to_select, { bypass_distances = true, bypass_times = true })
  end,
  can_use = function(self, player)
    return #table.filter(player:getCardIds("h"), function(cid, index, array)
      return Fk:getCardById(cid).trueName == "slash"
    end) > 0 or #player:getTableMark("@qunxian3__hanniba_shicai_nums-round") > 0
  end,
  on_use = function(self, room, skillUseEvent)
    local player = skillUseEvent.from
    local target_p = skillUseEvent.tos[1]
    room:notifySkillInvoked(player, "qunxian3__hanniba_pengren", "offensive")
    while #table.filter(player:getCardIds("h"), function(cid, index, array)
        return Fk:getCardById(cid).trueName == "slash"
      end) > 0 do
      local cid = table.find(player:getCardIds("h"), function(cid, index, array)
        return Fk:getCardById(cid).trueName == "slash"
      end)
      if cid == nil then break end
      local card = Fk:getCardById(cid)
      if target_p and card then
        room:setCardMark(card, "@@qunxian3__hanniba_pengren-card", 1)
        room:useCard({
          from = player,
          tos = { target_p },
          card = card,
          extraUse = true,
        })
      else
        break
      end
    end
    player:broadcastSkillInvoke("qunxian3__hanniba_pengren")
    local shicai_mark = player:getTableMark("@qunxian3__hanniba_shicai_nums-round")
    if #shicai_mark > 0 then
      local num = math.random(1, #shicai_mark)
      local random_shicai_mark = table.random(shicai_mark, num)
      local bingxiang_mark = player:getTableMark("@qunxian3__hanniba_bingxiang")
      local shiwu_mark = player:getTableMark("@[qunxian3__hanniba_pengren]")
      local shiwu = { "豆腐花", "炸翅膀", "牛排", "煎蛋" }
      local filter_shiwu = table.filter(shiwu, function(food, index, array)
        return not table.contains(shiwu_mark, food)
      end)
      local after_shicai_mark = table.filter(shicai_mark, function(shicai, index, array)
        return not table.contains(random_shicai_mark, shicai)
      end)
      if #after_shicai_mark == 0 then
        room:setPlayerMark(player, "@qunxian3__hanniba_shicai_nums-round", 0)
      else
        room:setPlayerMark(player, "@qunxian3__hanniba_shicai_nums-round", after_shicai_mark)
      end
      room:removePlayerMark(player, "qunxian3__hanniba_shicai_nums-round", 5 * num)
      for index, mark in ipairs(random_shicai_mark) do
        table.insertIfNeed(bingxiang_mark, mark)
      end
      room:setPlayerMark(player, "@qunxian3__hanniba_bingxiang", bingxiang_mark)
      if #filter_shiwu > 0 then
        table.insertTableIfNeed(shiwu_mark, table.random(filter_shiwu, math.min(num, #filter_shiwu)))
      end
      room:setPlayerMark(player, "@[qunxian3__hanniba_pengren]", shiwu_mark)
    end
  end
})

qunxian3__hanniba_pengren:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile or move.toArea == Card.DrawPile then
        for index, info in ipairs(move.moveInfo) do
          return Fk:getCardById(info.cardId):getMark("@@qunxian3__hanniba_pengren-card") ~= 0
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile or move.toArea == Card.DrawPile then
        for index, info in ipairs(move.moveInfo) do
          player.room:setCardMark(Fk:getCardById(info.cardId), "@@qunxian3__hanniba_pengren-card", 0)
        end
      end
    end
  end
})

qunxian3__hanniba_pengren:addEffect(fk.DamageCaused, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill("qunxian3__hanniba_pengren") and data.card and
        data.card.trueName == "slash" and data.card:getMark("@@qunxian3__hanniba_pengren-card") ~= 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askToSkillInvoke(player,
      { skill_name = "qunxian3__hanniba_pengren", prompt = "#qunxian3__hanniba_pengren-damage_slash" })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, "qunxian3__hanniba_pengren", "offensive")
    local skills = table.filter(data.to:getSkillNameList(), function(skill, index, array)
      return not player:hasSkill(skill, true)
    end)
    for index, skill in ipairs(data.to:getSkillNameList()) do
      room:invalidateSkill(data.to, skill, "-turn")
    end
    if data.to.faceup then
      data.to:turnOver()
    end
    if #skills == 0 then return end
    local choose_data = {
      path = "/packages/utility/qml/ChooseSkillBox.qml",
      data = {
        skills, 1, 1, "#qunxian3__hanniba_pengren-choose_skill"
      },
    }
    local req = Request:new(player, "CustomDialog")
    req:setData(player, choose_data)
    req:setDefaultReply(player, table.random(skills, 1))
    req.focus_text = self.name
    req:ask()
    skills = req:getResult(player)
    if #skills > 0 then
      room:handleAddLoseSkills(player, skills)
    end
  end
})

Fk:addQmlMark {
  name = "qunxian3__hanniba_pengren",
  how_to_show = function(name, value)
    if type(value) == "table" then
      return value
    end
    return ""
  end,
  qml_path = "packages/th_jie/qml/ZhidiBox"
}


return qunxian3__hanniba_pengren
